package copyengine.ui.infoTree.buildTree.builder
{
    import copyengine.infoTree.meta.CES9ScaleImageMeta;
    import copyengine.resource.CEResUtils;
    import copyengine.ui.display.s9.Scale9Image;
    import copyengine.ui.display.s9.Scale9Textures;
    import copyengine.ui.infoTree.buildTree.InfoTreeBuildUtils;

    import flash.geom.Rectangle;
    import flash.utils.Dictionary;

    import starling.display.DisplayObject;
    import starling.textures.Texture;

    public class InfoTreeBuilderS9 extends InfoTreeBuilderBasic
    {
        public function InfoTreeBuilderS9()
        {
            super();
        }

        override public function isCanHandleMeta(_meta:*):Boolean {return _meta is CES9ScaleImageMeta;}

        override public function getBuildResultMc(_meta:*, _quickFindDic:Dictionary, _quickFindKeyPR:String, _isRoot:Boolean):DisplayObject
        {
            var meta:CES9ScaleImageMeta = _meta as CES9ScaleImageMeta;
            var rawTexture:Texture = CEResUtils.getTextureFromAtlas(meta.textureMeta.textureFileName, meta.textureMeta.textureKey, mResProxy);

            var s9texture:Scale9Textures = new Scale9Textures(rawTexture, new flash.geom.Rectangle(meta.middleAreaRect.x,
                                                                                                   meta.middleAreaRect.y,
                                                                                                   meta.middleAreaRect.width,
                                                                                                   meta.middleAreaRect.height));
            var s9Img:Scale9Image = new Scale9Image(s9texture);
            s9Img.width = meta.width;
            s9Img.height = meta.height;
            InfoTreeBuildUtils.setBasicInfoByMeta(meta, s9Img);
            InfoTreeBuildUtils.addToQuickFindDic(s9Img, _quickFindDic, _quickFindKeyPR, _isRoot);
            return s9Img;
        }
    }
}
